# -*- coding: utf-8 -*-
# @Author    : Tian Wencheng
# @CreateTime: 2021/1/15 15:18
# @FileName  : business_management.py
# @IDE       : PyCharm
# @Git       : https://gitee.com/dianetian/projects


from common.request import HTTPRequest
from interface.base import BaseModule


class BusinessManagementModule(BaseModule):
    def __init__(self):
        self.request_url = ""
        self.request_method = ""
        self.request_headers = {"Content-Type": "application/json"}
        self.request_params = None
        self.cookies = super().cookies
        self.web_url = super().web_url

    def get_camera_added_event_type(self, **kwargs):
        camera_id = kwargs.get("cameraId")

        self.request_url = "/api/manager/checkCameraEvent"
        url = self.web_url + self.request_url
        self.request_method = "GET"
        self.request_params = {"cameraId": camera_id}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def get_camera_event_type_skylight(self, **kwargs):
        camera_id = kwargs.get("cameraId")
        event_type_id = kwargs.get("eventTypeId")

        self.request_url = "/api/skyLightPeriod"
        url = self.web_url + self.request_url
        self.request_method = "GET"
        self.request_params = {"cameraId": camera_id, "eventTypeId": event_type_id}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def add_camera_event_type_skylight(self, **kwargs):
        start_time = kwargs.get("startTime")
        end_time = kwargs.get("endTime")
        repeat_type = kwargs.get("repeatType")
        active = kwargs.get("active")
        remark = kwargs.get("remark")
        camera_id = kwargs.get("cameraId")
        event_type_id = kwargs.get("eventTypeId")

        self.request_url = "/api/skyLightPeriod"
        url = self.web_url + self.request_url
        self.request_method = "POST"
        self.request_params = {"startTime": start_time, "endTime": end_time, "repeatType": repeat_type,
                               "active": active, "remark": remark, "cameraId": camera_id, "eventTypeId": event_type_id}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def update_camera_event_type_skylight(self, **kwargs):
        id = kwargs.get("id")
        start_time = kwargs.get("startTime")
        end_time = kwargs.get("endTime")
        repeat_type = kwargs.get("repeatType")
        active = kwargs.get("active")
        remark = kwargs.get("remark")
        camera_id = kwargs.get("cameraId")
        event_type_id = kwargs.get("eventTypeId")

        self.request_url = "/api/skyLightPeriod"
        url = self.web_url + self.request_url
        self.request_method = "POST"
        self.request_params = {"id": id, "startTime": start_time, "endTime": end_time, "repeatType": repeat_type,
                               "active": active, "remark": remark, "cameraId": camera_id, "eventTypeId": event_type_id}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def delete_camera_event_type_skylight(self, **kwargs):
        id = kwargs.get("id")

        self.request_url = "/api/skyLightPeriod"
        url = self.web_url + self.request_url
        self.request_method = "DELETE"
        self.request_params = {"id": id}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def get_event_type(self, **kwargs):
        type = kwargs.get("type")

        self.request_url = "/api/manager/eventTypeSelect"
        url = self.web_url + self.request_url
        self.request_method = "GET"
        self.request_params = {"type": type}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def get_global_setting(self):
        self.request_url = "/api/manager/globalSet"
        url = self.web_url + self.request_url
        self.request_method = "GET"

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def update_global_setting(self, **kwargs):
        statistic_data_keep_time = kwargs.get("statistic_data_keep_time")

        self.request_url = "/api/manager/globalSet"
        url = self.web_url + self.request_url
        self.request_method = "PUT"
        self.request_params = {"statistic_data_keep_time": statistic_data_keep_time}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response
